package com.dyh.quickdemozwei.deliver;

import com.alibaba.fastjson.JSON;
import org.apache.commons.collections4.CollectionUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

public interface DeliverCommonDomain {

    static String gentKeys(Object... strArr){
        StringBuilder sb = new StringBuilder();
        for (Object str : strArr) {
            sb.append(str).append("#");
        }
        return sb.substring(0,sb.length()-1);
    }

    class Pkg{
        String id;
        String logisticsNumber;

        Long shippingId;
        String shippingName;
        String shippingCode;

        String shippingCodePlatform;

        public String getShippingCodePlatform() {
            return shippingCodePlatform;
        }

        public void setShippingCodePlatform(String shippingCodePlatform) {
            this.shippingCodePlatform = shippingCodePlatform;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getLogisticsNumber() {
            return logisticsNumber;
        }

        public void setLogisticsNumber(String logisticsNumber) {
            this.logisticsNumber = logisticsNumber;
        }

        public Long getShippingId() {
            return shippingId;
        }

        public void setShippingId(Long shippingId) {
            this.shippingId = shippingId;
        }

        public String getShippingName() {
            return shippingName;
        }

        public void setShippingName(String shippingName) {
            this.shippingName = shippingName;
        }

        public String getShippingCode() {
            return shippingCode;
        }

        public void setShippingCode(String shippingCode) {
            this.shippingCode = shippingCode;
        }
    }

    class PkgDetail{
        String id;
        String pkgId;
        String ogId;
        Integer num;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getPkgId() {
            return pkgId;
        }

        public void setPkgId(String pkgId) {
            this.pkgId = pkgId;
        }

        public String getOgId() {
            return ogId;
        }

        public void setOgId(String ogId) {
            this.ogId = ogId;
        }

        public Integer getNum() {
            return num;
        }

        public void setNum(Integer num) {
            this.num = num;
        }
    }

    class OrderGoods {
        String id;
        String orderId;
        String ooId;
        String oogId;
        String skuId;
        int num;
        int groupNum;

        public String getSkuId() {
            return skuId;
        }

        public void setSkuId(String skuId) {
            this.skuId = skuId;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getOrderId() {
            return orderId;
        }

        public void setOrderId(String orderId) {
            this.orderId = orderId;
        }

        public String getOoId() {
            return ooId;
        }

        public void setOoId(String ooId) {
            this.ooId = ooId;
        }

        public String getOogId() {
            return oogId;
        }

        public void setOogId(String oogId) {
            this.oogId = oogId;
        }

        public int getNum() {
            return num;
        }

        public void setNum(int num) {
            this.num = num;
        }

        public int getGroupNum() {
            return groupNum;
        }

        public void setGroupNum(int groupNum) {
            this.groupNum = groupNum;
        }
    }

    class OriginOrder{
        String id;
        String shippingStatus;

        public String getShippingStatus() {
            return shippingStatus;
        }

        public void setShippingStatus(String shippingStatus) {
            this.shippingStatus = shippingStatus;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }
    }

    class OriginOrderGoods{
        String id;
        String ooId;
        int num;
        int usedNum;

        String platformGoodsId;
        String platformOrderStatus;

        public String getPlatformGoodsId() {
            return platformGoodsId;
        }

        public void setPlatformGoodsId(String platformGoodsId) {
            this.platformGoodsId = platformGoodsId;
        }

        public String getPlatformOrderStatus() {
            return platformOrderStatus;
        }

        public void setPlatformOrderStatus(String platformOrderStatus) {
            this.platformOrderStatus = platformOrderStatus;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getOoId() {
            return ooId;
        }

        public void setOoId(String ooId) {
            this.ooId = ooId;
        }

        public int getNum() {
            return num;
        }

        public void setNum(int num) {
            this.num = num;
        }

        public int getUsedNum() {
            return usedNum;
        }

        public void setUsedNum(int usedNum) {
            this.usedNum = usedNum;
        }
    }


    class PkgReferenceInfosBase{
        protected Map<String, Pkg> pkgMap;
        protected Map<String, PkgDetail> pkgDetailMap;
        protected OneManyReference pkg2PkgDetailRef;
        protected ManyManyReference pkg2ogRef;

        protected Map<String, OrderGoods> ogMap;
        protected OneManyReference oo2ogRef;
        protected OneManyReference oog2og;
        protected Map<String, OriginOrder> ooMap;
        protected Map<String,  OriginOrderGoods> oogMap; //full
        protected OneManyReference oo2oog;


        //1og ~ tc 中对应sku数量
        Map<String,Integer> og2TcWeight = new HashMap<>();


        public Map<String, Integer> getOg2TcWeight() {
            return og2TcWeight;
        }

        public void setOg2TcWeight(Map<String, Integer> og2TcWeight) {
            this.og2TcWeight = og2TcWeight;
        }

        public ManyManyReference getPkg2ogRef() {
            return pkg2ogRef;
        }

        public void setPkg2ogRef(ManyManyReference pkg2ogRef) {
            this.pkg2ogRef = pkg2ogRef;
        }

        public OneManyReference getOog2og() {
            return oog2og;
        }

        public void setOog2og(OneManyReference oog2og) {
            this.oog2og = oog2og;
        }

        public Map<String, Pkg> getPkgMap() {
            return pkgMap;
        }

        public void setPkgMap(Map<String, Pkg> pkgMap) {
            this.pkgMap = pkgMap;
        }

        public Map<String, PkgDetail> getPkgDetailMap() {
            return pkgDetailMap;
        }

        public void setPkgDetailMap(Map<String, PkgDetail> pkgDetailMap) {
            this.pkgDetailMap = pkgDetailMap;
        }

        public OneManyReference getPkg2PkgDetailRef() {
            return pkg2PkgDetailRef;
        }

        public void setPkg2PkgDetailRef(OneManyReference pkg2PkgDetailRef) {
            this.pkg2PkgDetailRef = pkg2PkgDetailRef;
        }

        public Map<String, OrderGoods> getOgMap() {
            return ogMap;
        }

        public void setOgMap(Map<String, OrderGoods> ogMap) {
            this.ogMap = ogMap;
        }

        public OneManyReference getOo2ogRef() {
            return oo2ogRef;
        }

        public void setOo2ogRef(OneManyReference oo2ogRef) {
            this.oo2ogRef = oo2ogRef;
        }

        public Map<String, OriginOrder> getOoMap() {
            return ooMap;
        }

        public void setOoMap(Map<String, OriginOrder> ooMap) {
            this.ooMap = ooMap;
        }

        public Map<String, OriginOrderGoods> getOogMap() {
            return oogMap;
        }

        public void setOogMap(Map<String, OriginOrderGoods> oogMap) {
            this.oogMap = oogMap;
        }

        public OneManyReference getOo2oog() {
            return oo2oog;
        }

        public void setOo2oog(OneManyReference oo2oog) {
            this.oo2oog = oo2oog;
        }
    }

    class PkgReferenceInfos extends PkgReferenceInfosBase{

        ManyManyReference pkg2oogRef = new ManyManyReference();
        //子单占用
        NumberTable oogPkgOpNt = new NumberTable();

        // 把 pkg 和og 数量对齐
        //pkgNt ~ 有用的信息
        public StringBuilder matchPkgOg(){

            StringBuilder sb = new StringBuilder();
            NumberTable pkgNt = new NumberTable();
            NumberTable ogNt = new NumberTable();



//            System.out.println("未补完 og: "+ JSON.toJSONString(pkgNt));
            // 查看 og 多的


//            System.out.println("补完 og: "+ JSON.toJSONString(pkgNt));


            return sb;
        }


        public StringBuilder freshPkgOogRef(){
            StringBuilder sbErr = new StringBuilder();
            for (Map.Entry<String, Set<String>> entry : this.oog2og.getForwardMap().entrySet()) {
                String oogId = entry.getKey();

                for (String ogId : entry.getValue()) {
                    Set<String> pkgIds = this.pkg2ogRef.getReverse(ogId);
                    if (CollectionUtils.isEmpty(pkgIds)){
                        sbErr.append("找不到pkgIds ").append(ogId).append( ";");
                    }
                    else {
                        for (String pkgId : pkgIds) {
                            this.pkg2oogRef.updateByAuto(pkgId,oogId);
                        }
                    }
                }
            }

            return sbErr;
        };

        public StringBuilder calculateOogPkgOpMatrix(){
            StringBuilder sbErr = new StringBuilder();


            return sbErr;
        }


        public ManyManyReference getPkg2oogRef() {
            return pkg2oogRef;
        }

        public void setPkg2oogRef(ManyManyReference pkg2oogRef) {
            this.pkg2oogRef = pkg2oogRef;
        }

//        public SumMatrix getOogPkgOpMatrix() {
//            return oogPkgOpMatrix;
//        }
//
//        public void setOogPkgOpMatrix(SumMatrix oogPkgOpMatrix) {
//            this.oogPkgOpMatrix = oogPkgOpMatrix;
//        }
    }


}
